<?php
//验证码
session_start();
function verify_rand($length){
    $result = "";
    $string = "ABCDEFGHJKMNOPQRSTUVWXYZ";
    for ($i = 0 ; $i < $length ; $i++){
        if($i==0) $result .=$string[mt_rand(0 , strlen($string) - 1)];
		else $result .=$string[mt_rand(0 , strlen($string) - 1)];
    }
    return $result;
}
$zs=4;
$randcode=verify_rand($zs);
$_SESSION['verify_rand']=strtolower($randcode);
header ("content-type: image/png");
$image_x = 110;
$image_y = 33;
$image = imagecreate($image_x , $image_y);
$background_color = imagecolorallocate($image,0xf5,0xf5,0xf5);
$color[0] = imagecolorallocate($image,0xcc,0x00,0x99);
$color[1] = imagecolorallocate($image,0x00,0x00,0x00);
$color[2]  = imagecolorallocate($image,0xff,0x66,0x00);
$color[3] = imagecolorallocate($image,0xff,0x00,0x33);
$color[4]  = imagecolorallocate($image,0x00,0x00,0x99);
$color[5]  = imagecolorallocate($image,0x33,0x99,0x00);
//points
for($i=0;$i<100;$i++){
imagesetpixel($image,mt_rand(0,$image_x),mt_rand(0,$image_y),$color[mt_rand(0,count($color)-1)]);
}
//fonts
$fonts=array('BRITANIC.TTF','FTLTLT.TTF');

$rx = 6 + rand(1,15);

for($i=0;$i<$zs;$i++){
	$array = array(-2,1,2);
	$p = array_rand($array);
	$an = $array[$p]*mt_rand(-10,10);
	imagettftext($image, 25, $an, $i*mt_rand(20,23) + $rx,25, $color[mt_rand(0,count($color)-1)], "style/font/".$fonts[mt_rand(0,count($fonts)-1)],substr($randcode,$i,1) );
}

imagepng($image);
imagedestroy($image);
?>